<?php
include '../../../common.inc.php';
include 'fun.php';
$mysqli = new mysqli('localhost', 'root', '', 'test_data');
$sql = 'select * from koubei_myisam2 where import=0 order by id desc limit 100';
$result = $mysqli->query($sql);
$res = $result->fetch_all(MYSQLI_ASSOC);
if (!$res) exit('no more results');
foreach ($res as $r) {
	//
	//username
	//passport
	//company
	// password
	// payword
	// email
	// message 1
	// chat 0
	// sound 0
	// online 1
	// gender 1
	// truename
	// mobile
	// groupid 6
	// regid 6
	// areaid
	// regip  60.208.115.170
	// regtime time()
	// -- company
	// userid
	// username
	// groupid 6
	// validated 0
	// type '个体经营'
	// catid
	// areaid
	// telphone
	// adress

	$now = time();
	$sql = "insert into xd_member(userid	,username			   , passport			, company 		  		, password                       	, payword                         	, email					 	, message	, chat	, sound	, online	, gender	, truename			, mobile		 	, groupid	, regid	, areaid			, 		regip		, regtime	) values(
								  {$start}	, '{$r['py_lower']}'   , '{$r['py_lower']}' , '{$r['dianming']}'	, '14e1b600b1fd579f47433b88e8d85291', '14e1b600b1fd579f47433b88e8d85291','{$r['py_lower']}@163.com'	, 	1		,	   0,	0	,		  1 , 		1	, '{$r['dianming']}', '{$r['shouji']}'	, 6			, 	6	, '{$r['areaid']}'	, '60.208.115.170' 	, '{$now}'	)";
//	var_dump($sql);
	$insertid = $db->query($sql);
	$insertid = $db->insertId();
//	$insertid = 0;
	if ($insertid) {
		$sql = "insert into xd_company(
				userid		, username			,company			,groupid	, validated		, type				, catid				,catids			 , areaid			, telephone			, address		 , postcode		 , business) values (
				$insertid	, '{$r['py_lower']}', '{$r['dianming']}',6			, 0				, '{$r['type']}'	, '{$r['catid']}'	,'{$r['catids']}', '{$r['areaid']}'	, '{$r['dianhua']}'	, '{$r['dizhi']}', '{$r['aid']}' , '{$r['business']}')";
//		print_r($sql);
		$db->query($sql);

	} else {
		File::put('un.txt', File::get('un.txt')."\n".$r['ID']);
	}
	$sql = "update koubei_myisam2 set import=1 where id={$r['ID']}";
	$mysqli->query($sql);
	$start+=1;

}

echo '<meta http-equiv="refresh" content="0; url='.$_SERVER['PHP_SELF'].'?start='.$start.'" />';
echo '<pre style="font-size:60px;">';
echo $r['ID'];
exit();
?>